/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 *  \file     Mcu.h                                                                                     *
 *  \brief    This file contains interface header for MCU MCAL driver                                   *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2023/08/01     <td>1.0.0                                                                     *
 * </table>                                                                                             *
 *******************************************************************************************************/
#ifndef MCU_H
#define MCU_H

#ifdef __cplusplus
extern "C"
{
#endif
/**
 *
 * \defgroup MCAL_MCU MCU Driver
 * The Mcu Driver MCAL provides the service for basic microcontroller initialization.<br>
 * The Mcu Driver implements a standardized interface specified in the AUTOSAR_SWS_McuDriver document.<br>
 * The Mcu Driver is part of the AUTOSAR MCAL<br>
 * The Mcu Driver is implemented in two layers of E3 family,
 * one is the MCU service layer, which is mainly provide users with external interface functions for or mcu initialization,
 * clock initialization, ram initialization, activation of reduced power mode, reset and reset reason, etc.
 * And other is MCU_IP layer provide the hardware service layer, which is mainly responsible for registers reading and writing. etc. <br>
 *
 * \sa MCAL_MCU_MACRO
 * \sa MCAL_MCU_CFG
 * \sa MCAL_MCU_API
 *
 * \{
 */
/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
#include "Std_Types.h"
#include "Mcu_GeneralTypes.h"
/** Traceability       : SWSR_MCU_001*/
#include "Mcu_Cfg.h"
#include "Mcu_Reset.h"
#include "Mcu_Soc.h"
#include "Mcu_CkgenDrv.h"
#include "Mcu_KickCore.h"
#include "Mcu_ResetSig.h"
#include "Mcu_ClkCfgNode.h"
#include "Compiler.h"

/********************************************************************************************************
 *                                 Global Macro definition                                              *
 *******************************************************************************************************/
/**
 *  \defgroup MCAL_MCU_MACRO MCU Macro.
 *
 * This files defines MCU MCAL macros.
 *  @{
 */
#define MCU_FUNCTION_ENABLE (1U)
#define MCU_FUNCTION_DISABLE (0U)
/** \} */

/**
 *  \defgroup MCAL_MCU_API MCU API.
 *
 * This files defines MCU MCAL API.
 *  @{
 */
/** \} */

/**
 *  \defgroup MCAL_MCU_CFG MCU Configuration.
 *
 * This files defines MCU MCAL Configuration.
 *  @{
 */
/** \} */

/**
 *  \addtogroup MCAL_MCU_MACRO MCU Macro
 *  @{
 *
 */

/**
 *  \name Mcu Driver Module SW Version Info
 *
 *  Defines for MCU Driver version used for compatibility checks
 *  @{
 */

#define MCU_VENDOR_ID 0x8C
/** \} */
/** \} */
/********************************************************************************************************
 *                                  Global Types definition                                             *
 *******************************************************************************************************/


/** Traceability       : SWSR_MCU_009 SWSR_MCU_011*/
typedef enum
{
    MCU_PLL_LOCKED = 0x5Au,           /**< @brief PLL is locked. */
    MCU_PLL_UNLOCKED = 0xA5U,         /**< @brief PLL is unlocked. */
    MCU_PLL_STATUS_UNDEFINED = 0xF0U, /**< @brief PLL Status is unknown. */
} Mcu_PllStatusType;

typedef struct
{
    const Mcu_ClkConfigType *clkPrepare;
    const Mcu_ClkCgConfigType *clkEnable;
    const Mcu_ClkCgConfigType *clkDisable;
    const Mcu_ResetConfigType *rstDeassert;
    const Mcu_ResetConfigType *rstAssert;
} Mcu_ClockConfigType;


/**
* \brief   Mcu_ConfigType [SWS_Mcu_0024]
*
* \details A pointer to such a structure is provided to the MCU initialization routines for
*          configuration.
*/
/** Traceability       : SWSR_MCU_007 SWSR_MCU_008*/
typedef struct
{
    Mcu_RamSectionType numRamSections;
    Mcu_ClockType numClkCfgs;
#if (0U != MCU_MAX_RAMCFGS )
    const Mcu_RamConfigType (*ramCfgsPtr)[MCU_MAX_RAMCFGS];
#else
    const Mcu_RamConfigType (*ramCfgsPtr);
#endif
    const Mcu_ClockConfigType(*clkCfgsPtr)[MCU_MAX_CLKCFGS];
} Mcu_ConfigType;

/********************************************************************************************************
 *                                  Global Function Declarations                                        *
 *******************************************************************************************************/
#if defined(CFG_MULTI_CORE_OS)
extern const Mcu_ConfigType Mcu_Cfg[];
#else
extern const Mcu_ConfigType Mcu_Cfg;
#endif /**#if defined(CFG_MULTI_CORE_OS)*/

/** *****************************************************************************************************
 * \brief This service initializes the MCU driver.
 *
 * \verbatim
 * Syntax             : void Mcu_Init(const Mcu_ConfigType* ConfigPtr)
 *
 * Service ID[hex]    : 0x00
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : configPtr - Pointer to configuration set
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Driver Module Initialization function.The Initialization function shall
 *                      initialize the MCU module, i.e.make the configuration settings for
 *                      clock and RAM sections visible within the MCU module.
 * \endverbatim
 * Traceability       : SWSR_MCU_021 SWSR_MCU_054 SWSR_MCU_055 SW_SM002
 *                      SW_SM006
 *******************************************************************************************************/
void Mcu_Init(const Mcu_ConfigType *ConfigPtr);

/** *****************************************************************************************************
 * \brief This service initializes the PLL and other MCU specific clock options.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_InitClock(Mcu_ClockType ClockSetting)
 *
 * Service ID[hex]    : 0x02
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : ClockSetting - Clock setting id
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : ErrorId
 *
 * Description        : This service initializes the PLL and other MCU specific clock options.
 * \endverbatim
 * Traceability       : SWSR_MCU_004 SWSR_MCU_025 SWSR_MCU_026 SWSR_MCU_027
 *                      SWSR_MCU_046 SWSR_MCU_053 SWSR_MCU_054 SWSR_MCU_055
 *                      SW_SM006 SW_SM001
 *******************************************************************************************************/
Std_ReturnType Mcu_InitClock(Mcu_ClockType ClockSetting);

/** *****************************************************************************************************
 * \brief This service initializes the RAM section wise.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_InitRamSection(Mcu_RamSectionType RamSection)
 *
 * Service ID[hex]    : 0x01
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : RamSection - Selects RAM memory section provided in configuration set
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : ErrorId
 *
 * Description        : This service initializes the RAM section wise.
 * \endverbatim
 * Traceability       : SWSR_MCU_022 SWSR_MCU_023 SWSR_MCU_024 SWSR_MCU_046
 *                      SWSR_MCU_047 SWSR_MCU_054 SWSR_MCU_055 SW_SM006
 *                      SW_SM001
 *******************************************************************************************************/
Std_ReturnType Mcu_InitRamSection(Mcu_RamSectionType RamSection);

/** *****************************************************************************************************
 * \brief This service provides the lock status of the PLL.
 *
 * \verbatim
 * Syntax             : Mcu_PllStatusType Mcu_GetPllStatus(void)
 *
 * Service ID[hex]    : 0x04
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : PLL lock status
 *
 * Description        : This service provides the lock status of the PLL.
 * \endverbatim
 * Traceability       : SWSR_MCU_010 SWSR_MCU_028 SWSR_MCU_029 SWSR_MCU_030
 *                      SWSR_MCU_031 SWSR_MCU_054 SWSR_MCU_055 SW_SM001
 *******************************************************************************************************/
Mcu_PllStatusType Mcu_GetPllStatus(void);

/** *****************************************************************************************************
 * \brief The service reads the reset type from the hardware, if supported.
 *
 * \verbatim
 * Syntax             : Mcu_ResetType Mcu_GetResetReason(void)
 *
 * Service ID[hex]    : 0x05
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : reset type
 *
 * Description        : The service reads the reset type from the hardware, if supported.
 * \endverbatim
 * Traceability       : SWSR_MCU_003 SWSR_MCU_032 SWSR_MCU_033 SWSR_MCU_034
 *                      SW_SM001
 *******************************************************************************************************/
Mcu_ResetType Mcu_GetResetReason(void);

/** *****************************************************************************************************
 * \brief The service reads the reset type from the hardware register, if supported.
 *
 * \verbatim
 * Syntax             : Mcu_RawResetType Mcu_GetResetRawValue(void)
 *
 * Service ID[hex]    : 0x06
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : Reset raw value
 *
 * Description        : The service reads the reset type from the hardware register, if supported.
 * \endverbatim
 * Traceability       : SWSR_MCU_035 SWSR_MCU_036 SWSR_MCU_037 SW_SM001
 *******************************************************************************************************/
Mcu_RawResetType Mcu_GetResetRawValue(void);

/** Traceability       : SWSR_MCU_041*/
#if (STD_ON == MCU_PERFORM_RESET_API)
/** *****************************************************************************************************
 * \brief The service performs a microcontroller reset.
 *
 * \verbatim
 * Syntax             : Mcu_RawResetType Mcu_GetResetRawValue(void)
 *
 * Service ID[hex]    : 0x07
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : Reset raw value
 *
 * Description        : The service performs a microcontroller reset.
 *                      The function Mcu_PerformReset is only available if MCU_PERFORM_RESET_API is set to TRUE.
 *                      If set to FALSE, the function Mcu_PerformReset is not applicable
 * \endverbatim
 * Traceability       : SWSR_MCU_002 SWSR_MCU_038 SWSR_MCU_039 SWSR_MCU_040
 *                      SWSR_MCU_054 SWSR_MCU_055 SW_SM001
 *******************************************************************************************************/
void Mcu_PerformReset(void);
#endif /**#if (STD_ON == MCU_PERFORM_RESET_API)*/
/** *****************************************************************************************************
 * \brief This service activates the MCU power modes.
 *
 * \verbatim
 * Syntax             : __WEAK void Mcu_SetMode(Mcu_ModeType McuMode)
 *
 * Service ID[hex]    : 0x08
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : This service activates the MCU power modes(run mode)
 * \endverbatim
 *******************************************************************************************************/
void Mcu_SetMode(Mcu_ModeType McuMode);
#if (STD_ON == MCU_VERSION_INFO_API)
/** *****************************************************************************************************
 * \brief Get version information of this driver.
 *
 * \verbatim
 * Syntax             : void Mcu_GetVersionInfo(Std_VersionInfoType *versioninfo)
 *
 * Service ID[hex]    : 0x09
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : versioninfo - Pointer to where to store the version information of this module.
 *
 * Return value       : None
 *
 * Description        : This function returns the version information of this module
 *                      The version information include : Module ID, Vendor ID.
 *                      Vendor specific version numbers.
 *   -                  This function is available if the MCU_VERSION_INFO_API is set STD_ON
 *
 * \endverbatim
 * Traceability       : SWSR_MCU_044
 *******************************************************************************************************/
void Mcu_GetVersionInfo(Std_VersionInfoType *versioninfo);
#endif /**#if (STD_ON == MCU_VERSION_INFO_API) */

/** *****************************************************************************************************
 * \brief Clk set rate interface, set one clk node rate. will adaptively select parents.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_ClkSetRate(const Mcu_ClkNodeType *clkPtr, Mcu_ClkRateType rate, uint32 reserved1,
                              uint32 reserved2, uint32 reserved3)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : clkPtr - Pointer to clock node
 *                      rate - The clk rate to be set. for pll: pll vco rate.
 *                      reserved1 - for pll: ck0 rate.  for bus slice: cpu/axi/apb ratio. for ip slice: not used.
 *                      reserved2 - for pll: ck1 rate.  for bus slice: not used. for ip slice: not used.
 *                      reserved3 - for pll: spread config pointer. for bus slice: not used. for ip slice: not used.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errID
 *
 * Description        : Clock node frequency set. set one clk node(bus slice, ip slice or pll) rate.
 *                      will adaptively select parents.
 *                      This api not set the parent clock node, but will use the parent clock
 *                      node's rate to calculate divider's param.
 *                      you need consider clock divisible, to get high accuracy clock.
 *                      Some clk node may be not support Mcu_Ip_ClkSetRate api when it has child node.
 *                      This api always used for clock tree leaf node.
 *                      When setting the pll vco rate, ck0/ck1 should be set at the same time;
 *                      ck0/ck1 can also be set separately use this interface.
 *                      Be careful not to overclock and must be set according to TRM recommended flow.
 *                      Example: Mcu_ClkSetRate(CLK_NODE(g_ckgen_ip_enet1_tx), 250000000, 0, 0, 0)
 *                               Mcu_ClkSetRate(CLK_NODE(g_ckgen_bus_cr5_se_seip_r52), 600000000, CKGEN_BUS_DIV_4_2_1, 0, 0)
 *                               Mcu_ClkSetRate(CLK_NODE(g_pll1_vco), 2400000000, 400000000, 600000000, NULL_PTR)
 *                               Mcu_ClkSetRate(CLK_NODE(g_pll1_pll_ck0), 0, 400000000, 0, NULL_PTR)
 *                               Mcu_ClkSetRate(CLK_NODE(g_pll1_pll_ck1), 0, 0, 600000000, NULL_PTR)
 * \endverbatim
 * Traceability       : SW_SM006
 *******************************************************************************************************/
Std_ReturnType Mcu_ClkSetRate(const Mcu_ClkNodeType *clkPtr, Mcu_ClkRateType rate, uint32 reserved1,
                              uint32 reserved2, uint32 reserved3);
/** *****************************************************************************************************
 * \brief This function get clock rate(calculated by register value).
 *
 * \verbatim
 * Syntax             : Mcu_ClkRateType Mcu_ClkGetRate(const Mcu_ClkNodeType *clkPtr)
 *
 * Service ID[hex]    : 0x12
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : clkPtr - Pointer to clock node to get rate
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : clock rate value
 *
 * Description        : This function get clock rate.
 * \endverbatim
 * Traceability       : SWSR_MCU_004 SW_SM001
 *******************************************************************************************************/
Mcu_ClkRateType Mcu_ClkGetRate(const Mcu_ClkNodeType *clkPtr);

/** *****************************************************************************************************
 * \brief This function get clock rate(real rate by monitor).
 *
 * \verbatim
 * Syntax             : Mcu_ClkRateType Mcu_ClkGetMonitorRate(const Mcu_ClkNodeType *clkPtr)
 *
 * Service ID[hex]    : 0x18
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : clkPtr - Pointer to clock node to get rate
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : clock rate value
 *
 * Description        : This function get clock rate.
 * \endverbatim
 * Traceability       : SWSR_MCU_004 SW_SM001
 *******************************************************************************************************/
Mcu_ClkRateType Mcu_ClkGetMonitorRate(const Mcu_ClkNodeType *clkPtr);

/** *****************************************************************************************************
 * \brief This function enable/disable monitor clock source ready and clock active.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_CkgenMonReadyEnable(const Mcu_CkgenMonReadyType *ckgenMonReadyPtr, boolean enable)
 *
 * Service ID[hex]    : 0x20
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : ckgenMonReadyPtr - Pointer to clock monitor node
 *                      enable - TRUE/FALSE
 *                      typedef struct
                        {
                            uint32 base;
                            Mcu_ClkSliceType sliceType;(CKGEN_PCG_TYPE/CKGEN_BCG_TYPE/CKGEN_PLL_CG_TYPE/CKGEN_XTAL_CG_TYPE)
                            uint32 typeIndex;(slice id)
                            uint32 wdtTimeout;(wdtTimeout for xtal/pll ready)
                            uint8  monIntRes;(interrupt status, 0-no err, other-error occured)
                            uint32 realState;(real state)
                        } Mcu_CkgenMonReadyType;
 *
 * Parameters (out)   : None
 *
 * Return value       : errId. 0-OK, others- error
 *
 * Description        : This function enable/disable monitor clock source ready and clock active.
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
Std_ReturnType Mcu_CkgenMonReadyEnable(const Mcu_CkgenMonReadyType *ckgenMonReadyPtr, boolean enable);
/** *****************************************************************************************************
 * \brief This function monitor clock source ready and clock active.
 *
 * \verbatim
 * Syntax             : uint8 Mcu_CkgenMonReady(Mcu_CkgenMonReadyType *ckgenMonReadyPtr)
 *
 * Service ID[hex]    : 0x19
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : ckgenMonFreqPtr - Pointer to clock monitor node
 *                      typedef struct
                        {
                            uint32 base;
                            Mcu_ClkSliceType sliceType;(CKGEN_PCG_TYPE/CKGEN_BCG_TYPE/CKGEN_PLL_CG_TYPE/CKGEN_XTAL_CG_TYPE)
                            uint32 typeIndex;(slice id)
                            uint32 wdtTimeout;(wdtTimeout for xtal/pll ready)
                            uint8  monIntRes;(interrupt status, 0-no err, other-error occured)
                            uint32 realState;(real state)
                        } Mcu_CkgenMonReadyType;
 *
 * Parameters (out)   : None
 *
 * Return value       : clock monitor status
 *                      0 - the monitor status is ok
 *                      !0 - the monitor status is not ok
 *
 * Description        : This function monitor clock source ready and clock active.
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
uint8 Mcu_CkgenMonReady(Mcu_CkgenMonReadyType *ckgenMonReadyPtr);
/** *****************************************************************************************************
 * \brief This function enable/disable monitor clock rate.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_CkgenMonFreqEnable(const Mcu_CkgenMonFreqType *ckgenMonFreqPtr, boolean enable)
 *
 * Service ID[hex]    : 0x21
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : ckgenMonFreqPtr - Pointer to clock monitor node
 *                      enable - TRUE/FALSE
 *                      typedef struct
                        {
                            uint32 base;
                            Mcu_ClkSliceType sliceType;(CKGEN_IP_SLICE_TYPE/CKGEN_BUS_SLICE_TYPE/CKGEN_SF_BUS_SLICE_TYPE/CKGEN_FS24M_TYPE/CKGEN_PLL_CTRL_TYPE)
                            uint32 typeIndex;(slice id)
                            uint32 sliceFreq;(Expected frequency)
                            uint8  freqTolerantRat;(Threshold percentage)
                            uint8  monIntRes;(interrupt status, 0-Frequency within threshold range, 1-Frequency out of threshold range, 0xFF-error occured)
                            uint32 realFreq;(real frequency)
                        } Mcu_CkgenMonFreqType;
 *
 * Parameters (out)   : None
 *
 * Return value       : errId. 0-OK, others- error
 *
 * Description        : This function enable/disbale monitor clock rate.
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
Std_ReturnType Mcu_CkgenMonFreqEnable(const Mcu_CkgenMonFreqType *ckgenMonFreqPtr, boolean enable);
/** *****************************************************************************************************
 * \brief This function monitor clock rate.
 *
 * \verbatim
 * Syntax             : uint8 Mcu_CkgenMonFreq(Mcu_CkgenMonFreqType *ckgenMonFreqPtr)
 *
 * Service ID[hex]    : 0x13
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : ckgenMonFreqPtr - Pointer to clock monitor node
 *                      typedef struct
                        {
                            uint32 base;
                            Mcu_ClkSliceType sliceType;(CKGEN_IP_SLICE_TYPE/CKGEN_BUS_SLICE_TYPE/CKGEN_SF_BUS_SLICE_TYPE/CKGEN_FS24M_TYPE/CKGEN_PLL_CTRL_TYPE)
                            uint32 typeIndex;(slice id, for CKGEN_PLL_CTRL_TYPE: select slice type << 24 | slice id, slice type-0/1/2/3 ip/bus/core/ext)
                            uint32 sliceFreq;(Expected frequency)
                            uint8  freqTolerantRat;(Threshold percentage)
                            uint8  monIntRes;(interrupt status, 0-Frequency within threshold range, 1-Frequency out of threshold range, 0xFF-error occured)
                            uint32 realFreq;(real frequency)
                        } Mcu_CkgenMonFreqType;
 *
 * Parameters (out)   : None
 *
 * Return value       : clock monitor status
 *                      0 - the monitor status of clock rate is ok
 *                      !0 - the monitor status of clock rate is not ok
 *
 * Description        : This function monitor clock rate.
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
uint8 Mcu_CkgenMonFreq(Mcu_CkgenMonFreqType *ckgenMonFreqPtr);
/** *****************************************************************************************************
 * \brief This function enable/disable dbgMon monitor clock rate.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_CkgenDbgMonFreqEnable(const Mcu_CkgenMonFreqType *ckgenMonFreqPtr, boolean enable)
 *
 * Service ID[hex]    : 0x23
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : ckgenMonFreqPtr - Pointer to clock monitor node
 *                      enable - TRUE/FALSE
 *                      typedef struct
                        {
                            uint32 base;
                            Mcu_ClkSliceType sliceType;(CKGEN_IP_SLICE_TYPE/CKGEN_BUS_SLICE_TYPE/CKGEN_SF_BUS_SLICE_TYPE/CKGEN_EXT_TYPE)
                            uint32 typeIndex;(slice id)
                            uint32 sliceFreq;(Expected frequency)
                            uint8  freqTolerantRat;(Threshold percentage)
                            uint8  monIntRes;(interrupt status, 0-Frequency within threshold range, 1-Frequency out of threshold range, 0xFF-error occured)
                            uint32 realFreq;(real frequency)
                        } Mcu_CkgenMonFreqType;
 *
 * Parameters (out)   : None
 *
 * Return value       : errId. 0-OK, others- error
 *
 * Description        : This function enable/disbale dbgMon monitor clock rate.
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
Std_ReturnType Mcu_CkgenDbgMonFreqEnable(const Mcu_CkgenMonFreqType *ckgenMonFreqPtr, boolean enable);
/** *****************************************************************************************************
 * \brief This function monitor dbgMon clock rate.
 *
 * \verbatim
 * Syntax             : uint8 Mcu_CkgenDbgMonFreq(Mcu_CkgenMonFreqType *ckgenMonFreqPtr)
 *
 * Service ID[hex]    : 0x24
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : ckgenMonFreqPtr - Pointer to clock monitor node
 *                      typedef struct
                        {
                            uint32 base;
                            Mcu_ClkSliceType sliceType;(CKGEN_IP_SLICE_TYPE/CKGEN_BUS_SLICE_TYPE/CKGEN_SF_BUS_SLICE_TYPE/CKGEN_EXT_TYPE)
                            uint32 typeIndex;(slice id)
                            uint32 sliceFreq;(Expected frequency)
                            uint8  freqTolerantRat;(Threshold percentage)
                            uint8  monIntRes;(interrupt status, 0-Frequency within threshold range, 1-Frequency out of threshold range, 0xFF-error occured)
                            uint32 realFreq;(real frequency)
                        } Mcu_CkgenMonFreqType;
 *
 * Parameters (out)   : None
 *
 * Return value       : clock monitor status
 *                      0 - the monitor status of clock rate is ok
 *                      !0 - the monitor status of clock rate is not ok
 *
 * Description        : This function monitor dbgMon clock rate.
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
uint8 Mcu_CkgenDbgMonFreq(Mcu_CkgenMonFreqType *ckgenMonFreqPtr);
/** *****************************************************************************************************
 * \brief This function enable/disable monitor clock cqm.
 *
 * \verbatim
 * Syntax             : uint8 Mcu_CkgenMonCqmEnable(const Mcu_CkgenCqmType *ckgenCqmPtr, boolean enable)
 *
 * Service ID[hex]    : 0x22
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : ckgenCqmPtr - pointer to ckgencqm struct
 *                      enable - TRUE/FALSE
 *                      typedef struct
 *                      {
 *                          uint32 base;                (ckgen base )
 *                          uint32 cqmIndex;            (cqmIndex 0/1/2)
 *                          Mcu_CkgenType sliceType;    (slice type )
 *                          uint32 typeIndex;           (slice index )
 *                          uint8 dutyPercent;          (dutyPercent )
 *                          uint8 jitterPercent;        (jitterPercent )
 *                          uint8 dutyIntRes;           (interrupt status, 0-duty within threshold range, 1-duty out of threshold range, 0xFF-error occured )
 *                          uint8 jitterIntRes;         (interrupt status, 0-jitter within threshold range, 1-jitter out of threshold range, 0xFF-error occured )
 *                      } Mcu_CkgenCqmType;
 *
 * Parameters (out)   : None
 *
 * Return value       : clock monitor status
 *                      0 - the monitor status of clock cqm is ok
 *                      !0 - the monitor status of clock cqm is not ok
 *
 * Description        : This function monitor clock cqm.
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
uint8 Mcu_CkgenMonCqmEnable(const Mcu_CkgenCqmType *ckgenCqmPtr, boolean enable);
/** *****************************************************************************************************
 * \brief This function monitor clock cqm.
 *
 * \verbatim
 * Syntax             : uint8 Mcu_CkgenMonCqm(Mcu_CkgenCqmType *ckgenCqmPtr)
 *
 * Service ID[hex]    : 0x14
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : ckgenCqmPtr - pointer to ckgencqm struct
 *                      typedef struct
 *                      {
 *                          uint32 base;                (ckgen base )
 *                          uint32 cqmIndex;            (cqmIndex 0/1/2)
 *                          Mcu_CkgenType sliceType;    (slice type )
 *                          uint32 typeIndex;           (slice index )
 *                          uint8 dutyPercent;          (dutyPercent )
 *                          uint8 jitterPercent;        (jitterPercent )
 *                          uint8 dutyIntRes;           (interrupt status, 0-duty within threshold range, 1-duty out of threshold range, 0xFF-error occured )
 *                          uint8 jitterIntRes;         (interrupt status, 0-jitter within threshold range, 1-jitter out of threshold range, 0xFF-error occured )
 *                      } Mcu_CkgenCqmType;
 *
 * Parameters (out)   : None
 *
 * Return value       : clock monitor status
 *                      0 - the monitor status of clock cqm is ok
 *                      !0 - the monitor status of clock cqm is not ok
 *
 * Description        : This function monitor clock cqm.
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
uint8 Mcu_CkgenMonCqm(Mcu_CkgenCqmType *ckgenCqmPtr);

/** *****************************************************************************************************
 * \brief This function kickcore.
 *
 * \verbatim
 * Syntax             : void Mcu_SocKickCore(Mcu_KickCoreType core, uint32 entry)
 *
 * Service ID[hex]    : 0x15
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : core - core to reset
 *                      entry - vector table address for CR52 core and remap address for lp core
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : This function kickcore.
 * \endverbatim
 * Traceability       : SW_SM001
 *******************************************************************************************************/
void Mcu_SocKickCore(Mcu_KickCoreType core, uint32 entry);

/** *****************************************************************************************************
 * \brief This function read general register value.
 *
 * \verbatim
 * Syntax             : uint32 Mcu_ResetCtlGeneralRead(uint32 id)
 *
 * Service ID[hex]    : 0x16
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : id - general register id
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : general reg value,UINT32_MAX means error
 *
 * Description        : This function read general register value.
 * \endverbatim
 *******************************************************************************************************/
uint32 Mcu_ResetCtlGeneralRead(uint32 id);

/** *****************************************************************************************************
 * \brief This function Write general register value.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_ResetCtlGeneralWrite(uint32 id, uint32 val)
 *
 * Service ID[hex]    : 0x17
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : id - general register id
 *                      val - value to write
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      0 if success,
 *                      other error code.
 *
 * Description        : This function Write general register value.
 * \endverbatim
 *******************************************************************************************************/
Std_ReturnType Mcu_ResetCtlGeneralWrite(uint32 id, uint32 val);

/** *****************************************************************************************************
 * \brief This function switch FS24M/32K from RC to xtal.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_FsTrySwitchToXtal(uint32 base)
 *
 * Service ID[hex]    : 0X28
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : base - APB_FS_24M_BASE/APB_FS_32K_BASE
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      E_OK for success and others for failure.
 *
 * Description        : This function switch FS24M/32K from RC to xtal.
 * \endverbatim
 * Traceability       : SW_SM001
 *******************************************************************************************************/
Std_ReturnType Mcu_FsTrySwitchToXtal(uint32 base);

/** *****************************************************************************************************
 * \brief This function switch FS24M/32K from xtal to RC.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_FsTrySwitchToRC(uint32 base)
 *
 * Service ID[hex]    : 0x29
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : base - APB_FS_24M_BASE/APB_FS_32K_BASE
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      E_OK for success and others for failure.
 *
 * Description        : This function switch FS24M/32K from xtal to RC.
 * \endverbatim
 * Traceability       : SW_SM001
 *******************************************************************************************************/
Std_ReturnType Mcu_FsTrySwitchToRC(uint32 base);

/** *****************************************************************************************************
 * \brief This function used for debug to pull clock nodes to pad to measure frequency.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_CkgenClockToPad(const Mcu_ClkNodeType *ckgenPtr, uint8 divNum)
 *
 * Service ID[hex]    : 0x30
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : ckgenPtr - clock note with type Mcu_CkgenNodeType defined in "Mcu_ClkCfgNode.h"
 *                      divNum - frequency division, [1,15]
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      E_OK for success and others for failure.
 *
 * Description        : This function used for debug to pull clock nodes to pad to measure frequency.
 *                      GPIO_A9/A10/A11 need MUX CKGEN_SF.CLK_DBG, GPIO_LA4/LA5/LA6 need MUX CKGEN_LPP.CLK_DBG
 *
 * \endverbatim
 * Traceability       : SWSR_MCU_049 SW_SM001
 *******************************************************************************************************/
Std_ReturnType Mcu_CkgenClockToPad(const Mcu_ClkNodeType *ckgenPtr, uint8 divNum);

#if defined(LOWPOWER_SUPPORT_SUSPEND_RESUME)
/** *****************************************************************************************************
 * \brief This service suspend the MCU driver for lowpower.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_Suspend(void)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : This service suspend the MCU driver, just only used for lowpower.
 * \endverbatim
 * Traceability       : SWSR_MCU_054 SWSR_MCU_055
 *******************************************************************************************************/
Std_ReturnType Mcu_Suspend(void);

/** *****************************************************************************************************
 * \brief This service resume the MCU driver for lowpower.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_Resume(void)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : This service resume the MCU driver, just only used for lowpower.
 * \endverbatim
 * Traceability       : SWSR_MCU_054 SWSR_MCU_055
 *******************************************************************************************************/
Std_ReturnType Mcu_Resume(void);
#endif /* #if defined(LOWPOWER_SUPPORT_SUSPEND_RESUME) */
#ifdef __cplusplus
}
#endif

#endif /* MCU_H */
/* End of file */
